package chamster.maeander;

import java.util.List;

import chamster.MaeanderHamster;
import chamster.statemachine.HamsterState;

public class ForewardState extends MaeanderBasicState  {

	public List<HamsterState<MaeanderHamster>> applyState(
			List<HamsterState<MaeanderHamster>> states, MaeanderHamster hamster)
			throws Exception {
		if(hamster.canMoveForeward() && ! hamster.getView().canMoveLeft() 
				&& !hamster.getView().canMoveRight()) {
			hamster.foreward();
			states.add(this);
		}
		if(!hamster.canMoveForeward() && ! hamster.getView().canMoveLeft() 
				&& !hamster.getView().canMoveRight()) {
			hamster.turnAround();;
			states.add(this);
		}
		if(hamster.getView().canMoveRight() && hamster.canMoveForeward()) {
			states.add(new ForewardShiftRight());
		}
		if(hamster.getView().canMoveLeft() && hamster.canMoveForeward()) {
			states.add(new ForewardShiftLeft());
		}
		if(hamster.getView().canMoveLeft() && !hamster.canMoveForeward()) {
			hamster.turnLeft();
			states.add(new ForewardShiftLeft());
		}
		if(hamster.getView().canMoveRight() && !hamster.canMoveForeward()) {
			hamster.turnRight();
			states.add(new ForewardShiftRight());
		}
		return states;
	}

	public boolean isApplicable(MaeanderHamster hamster) {
		return true;
	}

}
